package employeeSalary;

import com.google.gson.Gson;
import com.mysql.cj.util.StringUtils;
import salaryEntity.emSalaryEntity;
import tools.BaseResponse;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import static salaryDao.employeeDao.totalCount;
import static salaryDao.employeeSalaryDao.getEmSalaryDao;


@WebServlet(urlPatterns = "/ssc/all/")
public class quireyEmSalary extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        String page=request.getParameter("page");
        String limit=request.getParameter("limit");
        BaseResponse<List<emSalaryEntity>> resp=new BaseResponse<>();
        List<emSalaryEntity> sti=getEmSalaryDao(StringUtils.isNullOrEmpty(page) ? 1 : Integer.parseInt(page),
                StringUtils.isNullOrEmpty(limit) ? 10 : Integer.parseInt(limit));
        resp.setCode(0);
        resp.setMsg("请求成功");
        resp.setData(sti);
        resp.setCount(totalCount());
        Gson gson=new Gson();
        String json=gson.toJson(resp);
//        System.out.printf("json"+json);
        PrintWriter out= response.getWriter();
        out.println(json);
        out.flush();
   }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
